package com.common.sdk.net.connect.http.interceptor;

import com.android.sohu.sdk.common.toolbox.LogUtils;
import com.common.sdk.net.connect.http.center.tools.HttpLog;
import com.common.sdk.net.connect.http.model.SohuIOException;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by chengjiangsang116630 on 2018/4/2.
 */

public abstract class ExceptionCatchedInterceptor implements Interceptor {

    private static final String TAG = "ExceptionCatchedInterceptor";

    @Override
    public Response intercept(Chain chain) throws IOException {
        try {
            return realIntercept(chain);
        } catch (Exception e) {
            if (e instanceof IOException) {
                throw e;
            } else {
                HttpLog.error(chain.request(), "Get Exception In Interceptor : " + e.getMessage(), e);
                throw new SohuIOException(e);
            }
        }
    }

    protected abstract Response realIntercept(Chain chain) throws IOException;
}
